<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            height: 400px;
            width: 400px;
            background-color: orange;
        }
    </style>

</head>
<body>
    <div class="box" id="d1">
        <p id="p1">AAAAAA</p>
    </div>
    <button onclick="addEle()">添加</button>
    <button onclick="delEle()">删除</button>
    <script>

        var div_d1 = document.getElementById("d1");
        var p_p1 = document.getElementById("p1");

        function delEle(){
            //删除页面元素
            p_p1.remove();
        }

        function addEle(){
            //创建一个新的页面元素 p
            var newP = document.createElement("p");
            //给p添加数据
            newP.innerText="BBBBB";
            //添加到页面内
            div_d1.appendChild(newP);

        }


    </script>

</body>
</html>